$(function () {
    var $houseSaleListPanel=SortForm.houseSaleListPanel;
    var getRewardList=SortForm.getRewardListUrl;
    var agentInfo=common.getLocalData('H5-agentInfo');
    var $loadingFail=SortForm.loadingFail;
    var token=common.getToken();
    var documentHeight=0;
    var windowHeight=0;
    var $resMsg=SortForm.resMsg;
    var sendData={
        pageNum:1,
        numPerPage:10,
        token:token,
        type:'',
        rewardStatus:'1'
    };
    requestData({
        url:getRewardList,
        sendData:sendData
    });
    $(window).on("scroll",function (e) {
        windowHeight=$(window).height();
        documentHeight=$(document).height();
        if($(this).scrollTop()+windowHeight==documentHeight){
            var formData=common.getSendDataByForm(SortForm.myForm);
                sendData = $.extend({}, sendData, formData);
            if(SortForm.flag){
                requestData({
                    url:getRewardList,
                    sendData:sendData
                });
            };
        }
    });
    function requestData(options) {
        var self=this;
        var url=options.url;
        var sendData=options.sendData;
        $.ajax({
            data:sendData,
            type: "POST",
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            dataType:"json",
            url:url,
            crossDomain:true,
            success:function(data){
                if(typeof data==="string"){
                    data=JSON.parse(data);
                }
                if(data.code==101 ||data.code==102){
                    console.log("token为空或者token失效");
                    window.location.href='login.html';
                };
                $resMsg.text("").hide();
                $loadingFail.hide();
                if(!!data && data['code']=="0"){
                    var totalNum=data.res.data.page.recordCount;
                    if(totalNum==0){
                         $houseSaleListPanel.html("");
                        $loadingFail.show();
                    }else{
                        data=data.res.data.record;
                        if(!data.length){
                            $resMsg.text("已经没有更多信息了").show();
                            SortForm.flag=false;
                        }else{
                            var responseDom=SortForm.buildListDomOfDataList({
                                loadingSelector:$resMsg,
                                imgBasePath:common.imageHost,
                                pageTargetType:"_self",
                                dataList:data
                            });
                            $houseSaleListPanel.append(responseDom);
                            sendData.pageNum++;
                            SortForm.flag=true;
                        };
                    };
                };
            },
            timeout:10000,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                common.errDialog("网络不畅，请稍后重试");  
            }
        });
    };
});